package com.xiyuan.smartutils.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 平台定义 PlatformType
 *
 * @author xiyuan-lgz 2023-09-16 @version v1.0.0 新建与整理
 */
public enum PlatformType {
    /**
     * 当前系统
     */
    SYS("A000", "系统", false),
    
    /**
     * 淘宝
     */
    Taobao("Taobao", "淘宝"),
    Taobao_TM("Taobao_TM", "天猫"),
    
    /**
     * 拼多多
     */
    PDD("Pdd", "拼多多"),
    
    /**
     * 京东
     */
    JD("JD", "京东"),
    
    /**
     * 抖音(抖店)
     */
    DouYin("DouYin", "抖音(抖店)"),
    /**
     * Tiktok
     */
    Tiktok("Tiktok", "抖音(Tiktok)"),
    /**
     * 快手(快手)
     */
    KuaiShou("KuaiShou", "快手"),
    
    /**
     * 淘特(淘特)
     */
    TaoTe("TaoTe", "淘特"),
    
    XianYu("XianYu", "咸鱼"),
    
    P1688("1688", "1688"),
    XIAO_HONG_SHU("xiaohongshu", "小红书"),
    Suning("suning", "苏宁"),
    /**
     * QQ
     */
    QQ("QQ", "QQ"),
    WeiXin("WeiXin", "微信"),
    
    MeiTuan("MeiTuan", "美团"),
    
    /**
     * 当当
     */
    Dangdang("Dangdang", "当当"),
    
    /**
     * 拍拍
     */
    PaiPai("PaiPai", "拍拍"),
    /**
     * 亚马逊
     */
    Amazon("Amazon", "亚马逊"),
    
    /**
     * 菜鸟
     */
    Cainiao("Cainiao", "菜鸟"),
    
    /**
     * 支付宝
     */
    Alipay("Alipay", "支付宝"),
    
    /**
     * 百度
     */
    Baidu("Baidu", "百度"),
    
    /**
     * 百度地图
     */
    BMap("BMap", " 百度地图"),
    
    /**
     * 高德地图
     */
    AMap("AMap", "高德地图"),
    
    /**
     * ChatGPT
     */
    ChatGPT("ChatGPT", "ChatGPT"),
    
    /**
     * 未知
     */
    UNKNOWN("unknown", "未知平台");
    
    @JsonValue
    @EnumValue
    private final String code;
    private final String name;
    private final boolean thirdParty;
    
    PlatformType(String code, String name, boolean thirdParty) {
        this.code = code;
        this.name = name;
        this.thirdParty = thirdParty;
    }
    
    PlatformType(String code, String name) {
        this.code = code;
        this.name = name;
        this.thirdParty = true;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getName() {
        return name;
    }
    
    public boolean isThirdParty() {
        return thirdParty;
    }
    
    public boolean eq(PlatformType type) {
        return this == type || (type != null && (this.name().equals(type.name()) || this.code.equals(type.getCode())));
    }
    
    public boolean eq(String type) {
        return (this.name().equals(type) || this.code.equals(type));
    }
    
    public static boolean isSupport(String code) {
        
        for (int i = 0; i < PlatformType.values().length; i++) {
            PlatformType value = PlatformType.values()[i];
            if (value.code.equals(code)) {
                return true;
            }
        }
        
        return false;
    }
    
    public static PlatformType of(String code) {
        PlatformType[] values = PlatformType.values();
        for (int i = 0; i < values.length; i++) {
            PlatformType value = values[i];
            if (value.name.equals(code) || value.code.equals(code)) {
                return value;
            }
        }
        
        return null;
    }
    
    /**
     * 判断是否为第三方平台
     *
     * @param code
     * @return
     */
    public static boolean isThirdParty(String code) {
        PlatformType type = of(code);
        return type != null && type.isThirdParty();
    }
}
